//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading;

using Shp.Runtime.Contract;

namespace Shp.Runtime.Services
{
    public class WorkflowService : IWorkflowSC
    {
        public void AddWorkflowDef(string name, string xoml)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InstalledUICulture;

            Guid tenantId = Context.TenantId;
            if (tenantId == Guid.Empty)
                throw new System.Security.SecurityException();

            WorkflowLogic.AddWorkflowDef(tenantId, name, xoml);
        }

        public void UpdateWorkflowDef(Guid workflowId, string name, string xoml)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InstalledUICulture;

            Guid tenantId = Context.TenantId;
            if (tenantId == Guid.Empty)
                throw new System.Security.SecurityException();

            WorkflowLogic.UpdateWorkflowDef(tenantId, workflowId, name, xoml);
        }

        public WorkflowDto GetWorkflowDef(Guid workflowId)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InstalledUICulture;

            Guid tenantId = Context.TenantId;
            if (tenantId == Guid.Empty)
                throw new System.Security.SecurityException();

            return WorkflowLogic.GetWorkflowDef(workflowId);
        }

        public Dictionary<Guid, string> GetWorkflowDefList()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InstalledUICulture;

            Guid tenantId = Context.TenantId;
            if (tenantId == Guid.Empty)
                throw new System.Security.SecurityException();

            return WorkflowLogic.GetWorkflowDefList(tenantId);
        }

        public void UpdateRuleSetDef(string markup)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InstalledUICulture;

            Guid tenantId = Context.TenantId;
            if (tenantId == Guid.Empty)
                throw new System.Security.SecurityException();

            WorkflowLogic.UpdateRuleSetDef(tenantId, markup);
        }

        public string GetRuleSetDef()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InstalledUICulture;

            Guid tenantId = Context.TenantId;
            if (tenantId == Guid.Empty)
                throw new System.Security.SecurityException();

            return WorkflowLogic.GetRuleSetDef(tenantId);
        }
    }
}
